package HIR.graph;

import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JPanel;

import org.jfree.chart.*;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.xy.*;

import HIR.relation.Table;

public class barGraph extends JPanel implements  gPanel {
	
	Table  valeurs;
	boolean xyplot =false;
	public barGraph(Table t) throws Exception{
		this.valeurs = t;
		
	 this.createPanel();
		
        
      
        

		
	}
	
	
	
	public barGraph(Table t, boolean b) throws Exception {
		this.valeurs = t ;
		this.xyplot = b;
		this.createPanel();
		// TODO Auto-generated constructor stub
	}



	public void createPanel() throws Exception
	{

		int nbreC = this.valeurs.getName().size();
		int nbreL = this.valeurs.getCard();
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		
		String Serie[] = new String[nbreC -1];
		for (int i =1 ; i <nbreC ; i ++ ) {
			Serie[i-1]  = (String) this.valeurs.getName().get(i);
		}
		String category[] = new String[nbreL];      
		for (int i =0 ; i <nbreL ; i ++ ) {
	
			category[i]  = (String) this.valeurs.get(i, 0);
			
		}
		

	        // column keys...
		for (int i =0 ; i <nbreL ; i ++ ) {
			for (int j =1 ; j <nbreC ; j ++ ) {
				dataset.addValue((Number) this.valeurs.get(i, j) , Serie[j-1],category[i] );
			}
		}

		
		
	

		JFreeChart chart = ChartFactory.createBarChart(
		            "Graph",         // chart title
		            "X",               // domain axis label
		            "Y",                  // range axis label
		            dataset,                  // data
		            PlotOrientation.VERTICAL, // orientation
		            true,                     // include legend
		            true,                     // tooltips?
		            false                     // URLs?
		        );
			
		
		//JFreeChart chart = ChartFactory.createXAreaChart("", "", "", xyDataset, PlotOrientation.HORIZONTAL, true, true, true);
		
		//JFreeChart chart =ChartFactory.createXYLineChart("", "", "", xyDataset, PlotOrientation.HORIZONTAL, true, true, true);
		ChartPanel crepart = new ChartPanel(chart);
		//crepart.setSize(100, 100);
		
		this.add(crepart);
		
		
	
	}

	public void decZoom() {
		// TODO Auto-generated method stub
		
	}

	public JPanel getPanel() {
		// TODO Auto-generated method stub
		return null;
	}

	public HIRJToolBar getToolbar() {
		// TODO Auto-generated method stub
		return null;
	}

	public void incZoom() {
		// TODO Auto-generated method stub
		
	}

	public void moveLeft() {
		// TODO Auto-generated method stub
		
	}

	public void moveLeft(int n) {
		// TODO Auto-generated method stub
		
	}

	public void moveRight() {
		// TODO Auto-generated method stub
		
	}

	public void moveRight(int n) {
		// TODO Auto-generated method stub
		
	}
	
	
}
